const app = getApp();
const Controller = require('../controllers/controllers.js').controller;
Page({
  data: {
    price:'',
    isloading:false,
  },
  onLoad() {

  },
  onShow(){
   this.info()
  },
  info(){
    Controller.info().then(res=>{
      if(res.data.baseData){
        this.setData({
          userInfo:res.data.baseData
        })
      }
    })
  },
  changeinput(e){
    let data = {};
    data[e.currentTarget.dataset.name]=e.detail.value
    this.setData(data)
  },
  save(){
    
    if(!this.data.price || this.data.price<=0){
      wx.showToast({
        title:"请输入提现金额",
        icon:"none"
      })
      return
    }
   
    if(this.data.price>this.data.userInfo.balance){
      wx.showToast({
        title:"提现金额不能大于赏金金额",
        icon:"none"
      })
      return
    }
    if(this.data.isloading){
      return
    }
    this.setData({
      isloading:true
    })
    var data={
      money:this.data.price
    }
    var that=this;
    Controller.withdrawal(data).then(res=>{
      wx.showToast({
        title:"提交成功",
        icon: 'success',
        duration: 1500
      })
      setTimeout(res => {
        that.setData({
          isloading:false
        })
      },1000)
      setTimeout(res => {
        wx.navigateBack({ //返回
          delta: 1
        })
      },1500)
    }).catch(res=>{
      setTimeout(res => {
        that.setData({
          isloading:false
        })
      },1000)
    })
    
  },
 
  onPageScroll: function (e) { // 获取滚动条当前位置
    
  },
  onShareAppMessage: function (e) {
    
  },
  onShareTimeline: function(res){
    
  },

})